Update type hints for linear search functions#14657
Conversation
for more information, see https://pre-commit.ci
mauricio812
left a comment
There was a problem hiding this comment.
Disculpen, soy nuevo en GitHub y me equivoqué de lugar al subir mi código. Ignoren mi actividad aquí, voy a crear mi propio repositorio."
There was a problem hiding this comment.
the function target parameter was explicitly set to int. It's good that the sequence is now set to list[int]. However, inside the documentation, it said "comparable items" and "item value to search". This could be misleading for the user since the algorithm explicitly expect only int value.
I think in this situation, you could either update the documentation too or update the algorithm parameters to a generic type. I suggest updating it to a generic one since the documentation already implies it should work on more types.
:param sequence: a collection with comparable items (sorting is not required for
linear search)
:param target: item value to search
Edit: I reviewed a similar PR #14615 (review) . After thinking through it more, I believe Sequence[T] is the right approach here. Please check the review to see more details.
Fixes #14592
Changes Made
linear_searchrec_linear_searchReason
This improves maintainability and aligns the implementation with modern Python typing practices.